import gov.nih.mipav.plugins.PlugInGeneric;
import gov.nih.mipav.view.ViewUserInterface;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JDialog;
import javax.swing.JPanel;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 * MIPAV plugin to segment tumors from multimodal MRI data
 * 
 * @author marco.zanger
 * 
 */
public class PlugInJSSegmentation implements PlugInGeneric {

	/** Contains all the model information to obtain the segmentation. */
	private DataManager jsData;

	/** Contains all the available methods to run. */
	private MethodManager jsMethods;

	/** Manage all the program status. */
	private StatusManager jsStatus;
 
	/** Time to log! */
	private Logger log = Logger.getLogger(PlugInJSSegmentation.class.getName());
	
	static JDialog jsPluginDialog;
	
	public void run() {

	  Logger.getRootLogger().setLevel(Level.ALL);
	  log.info("Segmentation plug-in is loading.");
	  
		ViewUserInterface mipavInterface = ViewUserInterface.getReference();
		jsData = DataManager.getInstance();
		jsMethods = MethodManager.getInstance();
		jsStatus = StatusManager.getInstance();

		PlugInJSSegmentation.jsPluginDialog = new JDialog(mipavInterface.getMainFrame());
		PlugInJSSegmentation.jsPluginDialog.setTitle("Segmentation Plug-In");

		JPanel generalPane = new JPanel();
		generalPane.setLayout(new BoxLayout(generalPane, BoxLayout.PAGE_AXIS));

		generalPane.add(jsData.drawContentPane());
		generalPane.add(jsMethods.drawContentPane());
		generalPane.add(jsStatus.drawContentPane());

		generalPane.setMinimumSize(new Dimension(200, 800));

		PlugInJSSegmentation.jsPluginDialog.getContentPane().setLayout(new BorderLayout(5, 5));
		PlugInJSSegmentation.jsPluginDialog.getContentPane().add(generalPane);

		PlugInJSSegmentation.jsPluginDialog.pack();
		PlugInJSSegmentation.jsPluginDialog.setResizable(false);

		System.gc();
		PlugInJSSegmentation.jsPluginDialog.setVisible(true);
	}
}
